package com.example.xksys.controller;

import com.example.xksys.utils.graph.CheckCode;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.util.*;


@RestController

public class ValidateCodeController {
@RequestMapping("/validateCode")
public void getPicInfo(HttpServletRequest request,HttpServletResponse response){
	CheckCode ck=new CheckCode(80,20,20,60);
	ck.formImage();
	try {
		ck.setServlertResponse(request,response);
	} catch (IOException e) {
		e.printStackTrace();
	}
}
@RequestMapping("/realCheckCode")
	public boolean VertifyCode(@RequestParam String code, HttpSession session)
	{
		if(session.getAttribute("codeStr")==null){
			return false;
		}
			String corret=(String)session.getAttribute("codeStr");
			if(code!=null&&code.equals(corret)){
				return true;
			}
			return false;
	}
}
